<template>
  <div>
    <el-form ref="form" :model="emitBlogData" label-width="80px" size="mini">
      <el-form-item label="标题">
        <el-input v-model="emitBlogData.blogTitle" />
      </el-form-item>
      <el-form-item label="分类">
        <el-select v-model="emitBlogData.blogType" clearable filterable placeholder="请选择" style="width: 100%">
          <el-option
            v-for="type in typeList"
            :key="type.typeId"
            :label="type.typeName"
            :value="type.typeId"
          />
        </el-select></el-form-item>
      <el-form-item label="封面">
        <el-upload
          class="avatar-uploader"
          :action="uploadUrl"
          :show-file-list="false"
          :on-success="uploadSuccess"
          :headers="headers"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon" />
        </el-upload>
      </el-form-item>
      <el-form-item label="内容">
        <tinymce v-model="emitBlogData.blogContent" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="emitBlogData.blogRemark" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">提交</el-button>
        <el-button size="mini" @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Tinymce from '@/components/Tinymce/index'
import blogApi from '@/api/blog'
import typeApi from '@/api/type'
  export default{

    components:{
      Tinymce
    },

    props:{
        emitBlogData:Object
        // emitBlogData:{
        //   type:Object,
        //   default:null
        // }
      },
    data(){
      return{
        typeList:{}
      }
    },
    methods:{
      onSubmit(){
        blogApi.updateBlog(this.emitBlogData).then(res=>{
         this.$message.success(res.message)
         this.$emit('onSubmit')
         this.$emit('closeUpdateDialog')
        })
      },
      //获取所有博客类型接口
        getAllType(){
          typeApi.getTypeList()
          .then(res=>{
            this.typeList = res.data.typeList
            console.log("typeList",res.data.typeList)
          })
        },
      onCancel(){
        this.$emit('closeUpdateDialog')
      }
    },
    created(){
      this.getAllType()
    }

  }
</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
